<?php

class Post_DataService_Post {

  public function getAllItem() {
    $db = Db::factory();
    $sql = "select * from post_item";
    return $db->fetchAll($sql);
  }

  public function addItem($data) {
    $db = Db::factory();
    $db->beginTransaction();
    try {
      $db->insert('post_item', $data);
      $id = $db->lastInsertId();
      $key = 'post.' . $id;
      $oid = DataService::addObject($id, 'Post_Object_Item');
      $db->query("update post_item set oid= :oid where id=  :id", array(
          'oid' => $oid,
          'id' => $id,
      ));
      $db->commit();
    } catch (Exception $e) {
      DataService::removeObject($oid);
      $db->rollBack();
      echo $e;
    }
  }

  public function getItemById() {
    
  }

  public function getLatestItem() {
    
  }

}